import 'dart:convert';

import 'package:oktoast/oktoast.dart';
import 'package:practice/data/entity/organ_entity.dart';
import 'package:practice/data/entity/user_info_entity.dart';
import 'package:practice/dto/case_info_dto.dart';
import 'package:practice/dto/case_list_dto.dart';
import 'package:practice/dto/exam_dto.dart';
import 'package:practice/dto/metting_dto.dart';
import 'package:practice/dto/online_class_dto.dart';
import 'package:practice/dto/online_class_info_dto.dart';
import 'package:practice/dto/online_class_infometion.dart';
import 'package:practice/dto/record_dto.dart';
import 'package:practice/dto/record_leave_dto.dart';
import 'package:practice/dto/remain_dto.dart';
import 'package:practice/dto/resource_dto.dart';
import 'package:practice/dto/resource_info_dto.dart';
import 'package:practice/dto/survey_dto.dart';
import 'package:practice/net/net_utils.dart';

class ServerConstants {
  ///======================离校生================================
  static const String news = "/business/news";
  static const String remain = 'business/todo/list';
  static const String onlineClass = 'business/online/course/list';
  static const String survey = 'business/survey/result/list';
  static const String exam = '/business/exam/list';
  static const String examOne = '/business/exam/';

  static const String surveyDetails = '/business/survey/detail';
  static const String surveyDetail = '/business/survey/detail/';
  static const String resource = '/business/resource/info/list';
  static const String onlineTimetable = '/business/online/timetable/list';

  static const String businessOnline = '/business/online/course/';
  static const String resourceInfo = '/business/resource/info/';
  static const String resultRecord = '/business/template/result/record/list';
  static const String surveyResult = '/business/survey/result';
  static const String meeting = '/business/meeting/list';
  static const String meetingOne = '/business/meeting/';
  static const String caseList = '/business/case/list';
  static const String caseInfo = '/business/case/';
  static const String caseAdd = '/business/case';

  ///======================在校生================================
}

class ServerApi {
  static Future news() async {
    Map<String, dynamic> data = {
      "newsContent": "123123123123123123",
      "newsTitle": "测试",
    };
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.news,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.POST);
    return response;
  }

  ///=====================离校生=======================================
  static Future caseAdd(title, tab, content) async {
    Map<String, dynamic> data = {
      "content": content,
      "tab": tab,
      "title": title,
      "status": 0,
      'userId': '361888213119512576'
    };
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.caseAdd,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.POST);

    print(response.toString());

    return response;
  }

  ///学习案例详情
  static Future caseInfo(id) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(
        ServerConstants.caseInfo + "" + id,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());

    return CaseInfoDto.fromJson(response);
  }

  static Future caseList() async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.caseList,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());

    return CaseListDto.fromJson(response);
  }

  static Future meetingOne(id) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(
        ServerConstants.meetingOne + "" + id,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());

    return response;
  }

  static Future meeting() async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.meeting,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());

    return MettingDto.fromJson(response);
  }

  static Future surveyResult(surveyResultVo) async {
    Map<String, dynamic> data = {'recordOptionList': surveyResultVo};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.surveyResult,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.POST);

    print(response.toString());

    return response;
  }

  ///查询云实践——模版调查结果试题记录列表
  static Future resultRecord(tempId, {rid}) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {'tempId': tempId, 'recordId': rid};
    var response = await NetUtils.practiceRequest(ServerConstants.resultRecord,
        queryParameters: params,
        data: data,
        isBody: false,
        method: NetUtils.GET);

    if (rid != null) {
      return RecordLeaveDto.fromJson(response);
    } else {
      return RecordDto.fromJson(response);
    }
  }

  static Future resourceInfo(id) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {'id': id};
    var response = await NetUtils.practiceRequest(
        ServerConstants.resourceInfo + "" + id,
        queryParameters: params,
        data: data,
        isBody: false,
        method: NetUtils.GET);

    return ResourceInfoDto.fromJson(response);
  }

  ///  获取云实践——在线课堂详细信息
  static Future businessOnline(onlineCourseId) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {'onlineCourseId': onlineCourseId};
    var response = await NetUtils.practiceRequest(
        ServerConstants.businessOnline + "" + onlineCourseId,
        queryParameters: params,
        data: data,
        isBody: false,
        method: NetUtils.GET);

    return OnlineClassInfometion.fromJson(response);
  }

  static Future resource({type}) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {'type': type};
    var response = await NetUtils.practiceRequest(ServerConstants.resource,
        queryParameters: params,
        data: data,
        isBody: false,
        method: NetUtils.GET);

    return ResourceDto.fromJson(response);
  }

  ///
  ///查询云实践——在线课堂课程列表

  static Future onlineTimetable(
    onlineCourseId,
  ) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {
      'onlineCourseId': onlineCourseId,
      'userId': "471967792794185728"
    };
    var response = await NetUtils.practiceRequest(
        ServerConstants.onlineTimetable,
        queryParameters: params,
        data: data,
        isBody: false,
        method: NetUtils.GET);
    print('======================================================');
    print(response.toString());

    return OnlineClassInfoDto.fromJson(response);
  }

  static Future surveyDetail(recordId) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(
        ServerConstants.surveyDetail + recordId.toString(),
        queryParameters: params,
        data: data,
        isBody: false,
        method: NetUtils.GET);
    print('======================================================');
    print(response.toString());

    return response;
  }

  //代办
  static Future surveyDetails(
    recordId,
    compName,
    jobName,
    salary,
  ) async {
    Map<String, dynamic> data = {
      'compName': compName,
      "id": 0,
      'jobName': jobName,
      'recordId': recordId,
      'salary': salary,
    };
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.surveyDetails,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.POST);
    print('======================================================');
    print(response.toString());

    return response;
  }

  ///查询云实践——考试信息列表
  static Future exam() async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.exam,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);
    print('======================================================');
    print(response.toString());
    ExamDto examDto = ExamDto.fromJson(response);
    return examDto;
  }

  static Future examOne(id) async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(
        ServerConstants.examOne + "" + id,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());

    return response;
  }

  //代办
  static Future<RemainDto> remain() async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {
      'userId': '361888213119512576',
      "type": 2,
    };
    var response = await NetUtils.practiceRequest(ServerConstants.remain,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());
    RemainDto remainDto = RemainDto.fromJson(response);
    return remainDto;
  }

  //在线课堂列表
  static Future<OnlineClassDto> onlineClass() async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.onlineClass,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());
    OnlineClassDto onlineClassDto = OnlineClassDto.fromJson(response);
    return onlineClassDto;
  }

  //就业调查列表
  static Future<SurveyDto> survey() async {
    Map<String, dynamic> data = {};
    Map<String, dynamic> params = {};
    var response = await NetUtils.practiceRequest(ServerConstants.survey,
        queryParameters: params,
        data: data,
        isBody: true,
        method: NetUtils.GET);

    print(response.toString());
    SurveyDto surveyDto = SurveyDto.fromJson(response);
    return surveyDto;
  }
}
